<?php
namespace Home\Controller;

class BoybookController extends AdminController
{	
	private $_model = null; //数据库操作类
	private $_book = null; //书籍表操作类

	//初始化操作
	public function _initialize(){
		$this->_model = D('Type');
		$this->_book = D('Book');
	}
	public function index(){

		$list = $this->_model->where('pid=1')->select();
		// var_dump($list);exit;
		$arr = array(); //声明一个空数组
		foreach($list as $v){
			$book = $this->_book->where(array('typeid'=>array('eq',$v['id'])))->select();			
			//定义空数组
			$books = array();
			//遍历
			foreach($book as $value){
				$books[] =  $value;			
			}
			$v['book'] = $books; //将新得到角色信息放置到$v中
			$arr[] = $v;
		}
		//分配变量
		$this->assign("list",$arr);
		$this->assign("title","乐阅网");
		// $this->assign("user",$user);
		//加载模板
		$this->display('Boybook/index');
	}






}